{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自我诊疗界面</title>
    <!-- 引入 layui.css -->
    <link href="{%static '/css/layui.css'%}" rel="stylesheet">
    <link href="{%static '/css/section.css'%}" rel="stylesheet">
    <link href="{%static '/css/font-awesome.min.css'%}" rel="stylesheet">
</head>
<body>

<!--诊疗工具栏-->

    <div class="layui-container">
        <div type="text-align:center;">
        <a href="javascript:;" class="layui-btn layui-btn-sm" data-content-href="zhenliao?type=self" data-title="自我诊断" data-icon="fa fa-gears">自我诊断</a>
        <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" data-content-href="zhenliao?type=major" data-title="专业诊断" data-icon="fa fa-gears">专业诊断</a>
        </div>
            <!--        自我诊断的界面-->

            <div class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline" pane>
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" name="name" id="name" value="{{full_name}}" lay-verify="required" autocomplete="off" lay-reqtext="姓名" class="layui-input" />
                        </div>
                        <label class="layui-form-label">生日</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" name="birthday" id="birthday" value="" lay-verify="required" autocomplete="off" lay-reqtext="姓名" class="layui-input" />
                        </div>
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="radio" name="sex" value="男" title="男" {{sex_male}}>
                            <input type="radio" name="sex" value="女" title="女" {{sex_fmale}}>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">体温</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" name="body_temperature" id="body_temperature" lay-verify="required" autocomplete="off" lay-reqtext="体温" lay-affix="number" step="0.01" lay-precision="2" min="34" max="45" class="layui-input" />
                        <div class="layui-input-suffix">
                           ℃
                        </div>
                    </div>
                    <label class="layui-form-label">饮食</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="text" name="diet" id="diet" value="" lay-verify="required" autocomplete="off" lay-reqtext="饮食" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否疼痛</label>
                    <div class="layui-input-inline layui-input-wrap">
                         <input type="checkbox" name="is_pain" value="true" title="疼痛">
                    </div>
                    <label class="layui-form-label">疼痛部位</label>
                    <div class="layui-input-inline layui-input-wrap">
                         <input type="text" name="pain_area" id="pain_area" value="" lay-reqtext="疼痛部位" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">目前症状</label>
                        <div class="layui-input-block">
                          <textarea id="symptom" placeholder="目前症状" class="layui-textarea"></textarea>
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">既往病史</label>
                        <div class="layui-input-block">
                          <textarea id="medical_history" placeholder="既往病史" class="layui-textarea"></textarea>
                        </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">自我判断</label>
                        <div class="layui-input-block">
                          <textarea id="self_judgment" placeholder="自我判断" class="layui-textarea"></textarea>
                        </div>
                </div>
            </div>
            <button type="button" id="btn_save" class="layui-btn layui-btn-primary">保存</button>&nbsp;&nbsp;&nbsp;
            <button type="button" id="btn_cancel" class="layui-btn layui-btn-primary">取消</button>
        <br/>
        <br/>
        <br/>
    </div>

<!-- 引入 layui.js -->
<script src="{%static '/js/layui.min.js'%}" charset="utf-8"></script>
<script>

    layui.use(['layer','jquery','table','laydate','form'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table,
            laydate = layui.laydate,
            form = layui.form;

            laydate.render({
            elem:"#birthday"
            });

            $("#btn_save").click(function(){

               var name = $("#name").val()
               var birthday = $("#birthday").val()
               var sex = $("input[name='sex']:checked").val();
               is_pain = $("input[name='is_pain']:checked").val();

               url="/api/diagnose/diagnose/"
               $.ajax({
               url:url,
               type:'post',
               data:{
                   "name":name,
                   "birthday":birthday,
                   "sex":sex,
                    "symptom":$("#symptom").val(),
                    "medical_history":$("#medical_history").val(),
                    "body_temperature":$("#body_temperature").val(),
                    "diet":$("#diet").val(),
                    "is_pain":is_pain,
                    "pain_area":$("#pain_area").val(),
                    "self_judgment":$("#self_judgment").val(),
                    "star_user":{{user_id}}
               },
               dataType:"json",
               success:function(res){
                   if(res.code==200){
                       layer.msg(res.msg)
                   }
                   else{
                       layer.msg(res.msg,{time:1*1000});
                   }
               },
               error:function(err){
                   layer.msg("修改出错",{time:1*1000});
               }
             });


            });
            table.render({
               elem:"#infoDrug",
               url:"/api/prescription/drug?prescrption_id={{prescription_id}}",
               height:'full-215',
               page:true,
               cols:[[
                   {toolbar:'#drugBar',title:"操作",width:140,fixed:'right'},
                   {title:'序号',width:70,type:"numbers"},
                   {field:'MedCd',title:"药品编号" },
                   {field:'MedNm',title:"药品名称" },
                   {field:'MedSpec',title:"药品规格" },
                   {field:'MedNote',title:"药品备注" },
                   {field:'drtscd',title:"服药备注" },
                   {field:'doselist_time',title:"服药时间" },
                   {field:'doselist_dose',title:"服药剂量" },
               ]],
               //修改参数
               request:{
                   "pageName":"pageNum",
                   "limitName":"pageSize"
               },
               response:{
                   statusName:'code',     //数据状态的字段名称，默认：codes
                   countName: 'count',    //数据总数的字段名称，默认：count
                   dataName:'data',       //数据列表的字段名称，默认：data
               },
               parseData:function(res){
                   d = {
                       "code":0,
                       "count":res.data.count,
                       "data":res.data.results
                   }
                   return d
               }
            });
    });
</script>
</body>
</html>